#ifndef DISPLAYER_H
#define DISPLAYER_H

#include <QWidget>
#include "DrawParam.h"

namespace Ui {
class Displayer;
}

class CBaseImage;
class Displayer : public QWidget
{
    Q_OBJECT

public:
    explicit Displayer(QWidget *parent = nullptr);
    ~Displayer();

    bool LoadFile(QString fn);
    void SetImage(CBaseImage* pImg);
    bool isLoaded();
    DrawParam& GetDrawParam() {
        return m_drawParam;
    }

    CBaseImage* GetImage() {
        return m_pImage;
    }

    void PrevFrame();
    void NextFrame();

    // format = 0 jpg, 1 png, 2 tiff
    bool Export(std::string dst, int format);

protected:
    void paintEvent(QPaintEvent* event) override;
    void resizeEvent(QResizeEvent*) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    void wheelEvent(QWheelEvent *event) override;

private:
    Ui::Displayer *ui;

    void drawText(QPainter& p);

    CBaseImage* m_pImage = nullptr;
    QPixmap m_pix;
    void* m_pDib = nullptr;
    DrawParam m_drawParam;

    enum MouseAction {
        MA_None,
        MA_Window,   // 调窗
        MA_Pan,      // 移动
        MA_Scale     // 缩放
    };

    MouseAction m_action = MA_None;
    QPoint m_lastPos;
};

#endif // DISPLAYER_H
